<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>js表达式</h2>
      <button v-on:click="count++">btn</button>
      <p>count: {{ count }}</p>
      <!-- 双大括号和v-bind里面是可以直接使用js表达式的 -->
      <!-- 数字运算, 三目, 字符串拼接, 对象和数组的点操作符, js的api -->
      <p :title="count * 2">doubleCount: {{ count * 2 }}</p>
      <p>{{ sex === 1 ? "男" : "女" }}</p>
      <p>{{ str + "!!!" }}</p>
      <p>name: {{ obj.name }}</p>
      <p>arr: {{ arr[1] }}</p>
      <p>reverseStr2: {{ str2.split("").reverse().join("") }}</p>

      <!-- 动态属性, 了解 -->
      <img :[attr]="url" alt="" />
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      const app = createApp({
        data() {
          return {
            count: 1,
            sex: 2,
            str: "hi",
            obj: {
              name: "zs",
              age: 18,
            },
            arr: [1, 2, 3, 4],
            str2: "hello vue!",

            url: "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png",
            attr: "data-src",
          };
        },
        // mounted相当于window.onload
        mounted() {
          setTimeout(() => {
            this.attr = "src";
          }, 2000);
        },
      });
      app.mount("#app");
    </script>
  </body>
</html>
